package com.example.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.product.entity.Category;
import com.example.product.mapper.CategoryMapper;
import com.example.product.service.CategoryService;
import com.example.product.util.TokenUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
 * 管理员业务处理
 **/
@Service
@Transactional
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Autowired
    private TokenUtil tokenUtil;

    @Autowired
    private CategoryMapper categoryMapper;


//    private Account convertCategoryToAccount(Category category) {
//        Account account = new Account();
//        account.setId(category.getId());
//        account.setUsername(category.getUsername());
//        account.setName(category.getName());
//        account.setRole(category.getRole());
//        account.setImg(category.getImg());
//        return account;
//    }

    @Override
    /**
     * 新增
     */
    public void add(Category category) {
        categoryMapper.insert(category);
    }

    /**
     * 删除
     */
    @Override
    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }

    @Override
    public boolean saveBatch(Collection<Category> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<Category> entityList, int batchSize) {
        return false;
    }

    /**
     * 修改
     */
    @Override
    public boolean updateById(Category category) {
        categoryMapper.updateById(category);
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<Category> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(Category entity) {
        return false;
    }

    @Override
    public Category getOne(Wrapper<Category> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Optional<Category> getOneOpt(Wrapper<Category> queryWrapper, boolean throwEx) {
        return Optional.empty();
    }

    @Override
    public Map<String, Object> getMap(Wrapper<Category> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<Category> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    @Override
    public CategoryMapper getBaseMapper() {
        return null;
    }

    @Override
    public Class<Category> getEntityClass() {
        return null;
    }

    /**
     * 根据ID查询
     */
    @Override
    public Category selectById(Integer id) {
        return categoryMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    @Override
    public List<Category> selectAll(Category category) {
        return categoryMapper.selectAll(category);
    }

    /**
     * 分页查询
     */
    @Override
    public PageInfo<Category> selectPage(Category category, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Category> list = categoryMapper.selectAll(category);
        return PageInfo.of(list);
    }


}